package com.briup.store.web.controller;

import com.briup.common.response.Result;
import com.briup.common.utils.UserContext;
import com.briup.store.domain.dto.UserLoginDTO;
import com.briup.store.service.UserService;
import com.briup.store.domain.vo.UserGetInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/auths")
public class AuthController {

    @Autowired
    private UserService userService;

    /**
     * 登录功能
     */
    @PostMapping
    public Result login(@RequestBody UserLoginDTO userLogin){
        String jwt = userService.login(userLogin);
        return Result.success(jwt);
    }


    /**
     * 获取当前用户信息
     */
    @GetMapping
    public Result getUserInfo(){
        UserGetInfoVO userGetInfo = userService.getUserInfo(UserContext.getUser());
        return Result.success(userGetInfo);
    }


    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public Result logout() {
        log.info("用户 " + UserContext.getUser() + " logout success!");
        return Result.success();
    }
}
